package kr.hyunist.androidcomplete01saeildamil.ch19;

import kr.hyunist.androidcomplete01saeildamil.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class ThreadEx02 extends Activity {
	int mMainValue = 0;
	int mBackValue = 0;
	TextView mMainText;
	TextView mBackText;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.threadtest01);
		
		mMainText = (TextView) findViewById(R.id.threadtesttv1);
		mBackText = (TextView) findViewById(R.id.threadtesttv2);
		
		BackRunnable runnable = new BackRunnable();
		Thread th = new Thread(runnable);
		th.setDaemon(true);
		th.start();
	}
	
	class BackRunnable implements Runnable {

		@Override
		public void run() {
			while(true){
				mBackValue++;
				try {
					Thread.sleep(1000);
				} catch(InterruptedException e){
					e.getStackTrace();
				}
			}
		}
		
	}
	
	public void mOnClick(View v){
		mMainValue++;
		mMainText.setText("MainValue : " + mMainValue);
		mBackText.setText("BackValue : " + mBackValue);
	}
}
